{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    <form class="mb-20" method="get" action="{:\\think\\Url::build($Request.action)}">
        <input type="hidden" name="group_id" value="{$group_id}">
        <input type="text" class="input-text" style="width:250px" placeholder="姓名" name="realname" value="{$Request.param.realname}">
        <input type="text" class="input-text" style="width:250px" placeholder="手机号" name="mobile" value="{$Request.param.mobile}">
        <input type="text" class="input-text" style="width:250px" placeholder="车类型" name="car_type" value="{$Request.param.car_type}">
        <input type="text" class="input-text" style="width:250px" placeholder="车辆品牌" name="car_brand" value="{$Request.param.car_brand}">
        <input type="text" class="input-text" style="width:250px" placeholder="汽车型号" name="car_model" value="{$Request.param.car_model}">
        <input type="text" class="input-text" style="width:250px" placeholder="座位数" name="seats" value="{$Request.param.seats}">
        <input type="text" class="input-text" style="width:250px" placeholder="请输入民族" name="nationality" value="{$Request.param.nationality}">
        <div   style="width:250px;display: inline-block" >
            <select name="driver_rank_id" class="select2 " id="driver_rank_id">
                <option value="">选择等级</option>
                {volist name="ranks" id="rank"}
                <option value="{$rank.id}">{$rank.name}</option>
                {/volist}
            </select>
        </div>
        <div   style="width:250px;display: inline-block" >
            <select name="tag" class="select2 " id="tag">
                <option value="">选择标签</option>
                {volist name="driver_tags" id="driver_tag"}
                <option value="{$driver_tag['id']}"  >{$driver_tag['chinese']}</option>
                {/volist}
            </select>
        </div>
        <button type="submit" class="btn btn-success" id="realname_btn" name=""><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
    </form>
    <!--select2 js 插件-->
    <script type="text/javascript" src="__LIB__/select2-4.0.3/dist/js/select2.min.js"></script>
    <!--select2样式 start -->
    <link href="__LIB__/select2-4.0.3/dist/css/select2.min.css" rel="stylesheet" />
    <?php use think\Db; ?>
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            派单号:{$group.id} &nbsp;&nbsp; 标题: {$group.title|mb_substr=0,20}...... &nbsp;&nbsp; 开始时间: <?php $start_time = empty($group['go_date'])?'':date('Y-m-d',$group['go_date']); echo $start_time; ?>
            &nbsp;&nbsp;结束时间:<?php $end_time = empty($group['end_date'])?'':date('Y-m-d',$group['end_date']); echo $end_time; ?>
        </span>
        <span class="r pt-5 pr-5">
            {php}
                if(!empty($outOfServiceDrivers))
                    $count = count($outOfServiceDrivers) + count($driverInService);
                else
                    $count = 0;
            {/php}
            共有数据 ：<strong>{$count ?? '0'}</strong> 条
        </span>
        <br>
    <form id="form55" action="###" method="post" onsubmit="return false">
    <input type="hidden" name="id" value="{$group_id ?? ''}">
    <table class="table table-border table-bordered table-hover table-bg mt-20">
        <thead>
        <tr class="text-c">
            <th width="25"></th>
            <th width="">user_id</th>
            <th width="">用户名</th>
            <th width="">民族</th>
            <th width="">电话</th>
            <th width="">座位数</th>
            <th width="">车类型</th>
            <th width="">车辆品牌</th>
            <th width="">汽车型号</th>
            <th width="">是否在服务中</th>
            <th width="">派单量(进行中和已派单)</th>
            <th width="">派单</th>
            <th width="">开始时间</th>
            <th width="">结束时间</th>
            <th width="">司机等级</th>
            <th width="">标签</th>
        </tr>
        </thead>
        <tbody>
        <!--没有服务的司机-->
        {if !empty($outOfServiceDrivers)}
        <tr class="text-c">
            <td colspan="16">不在服务中的司机</td>
        </tr>
        {/if}
        <tbody>
        {volist name="outOfServiceDrivers" id="driver_user"}
        <tr class="text-c">
            <td><input type="radio" name="driver_user_id" value="{$driver_user.user_id}" data-realname="{$driver_user.realname}" data-user_id="{$driver_user.user_id}" data-account="{$driver_user.account}"></td>
            <td>{$driver_user.user_id}</td>
            <td>{$driver_user.realname}</td>
            <td>{$driver_user.nationality}</td>
            <td>{$driver_user.phone}</td>
            <td>{$driver_user.seats}</td>
            <td>
                {$driver_user.arctic}
            </td>
            <td>
                {$driver_user.brand_name}
            </td>
            <td>
                {$driver_user.car_model}
            </td>
            <td>{$driver_user.inservice?"服务中":"不在服务"}</td>
            <td>{php}echo count($driver_user['dispatchOrder']); {/php}</td>
            <td    style="padding: 0px;">
                {php}
                if($driver_user['dispatchOrder']){
                $count = count($driver_user['dispatchOrder']);
                $i = 1;
                foreach($driver_user['dispatchOrder'] as $key08=>$val08){
                $i++;
                $status = '';
                switch($val08['dispatch_group_status']){
                case 'undistributed'; $status = '未派单'; break;
                case 'sendorders'; $status = '待接单'; break;
                case 'proceed'; $status = '进行中'; break;
                case 'achieve'; $status = '已完成'; break;
                case 'accounts'; $status = '已结算'; break;
                }
                echo "<span>";
                            echo $val08['id'].':'.$status;
                            echo "</span>";
                if(!($i > $count)){
                echo "<hr  width='100%' noshade='#000'/>";
                }
                }
                }
                {/php}
            </td>
            <td    style="padding: 0px;">
                {php}
                if($driver_user['dispatchOrder']){
                $count = count($driver_user['dispatchOrder']);
                $i = 1;
                foreach($driver_user['dispatchOrder'] as $key08=>$val08){
                $i++;
                $go_date = '';
                if(!empty($val08['go_date'])){
                $go_date = date('Y-m-d',$val08['go_date']);
                }
                echo "<span>";
                        echo $go_date;
                        echo "</span>";
                if(!($i > $count)){
                echo "<hr  width='100%' noshade='#000'/>";
                }
                }
                }
                {/php}
            </td>
            <td    style="padding: 0px;">
                {php}
                if($driver_user['dispatchOrder']){
                $count = count($driver_user['dispatchOrder']);
                $i = 1;
                foreach($driver_user['dispatchOrder'] as $key08=>$val08){
                $i++;
                $end_date = '';
                if(!empty($val08['end_date'])){
                $end_date = date('Y-m-d',$val08['end_date']);
                }
                echo "<span>";
                            echo $end_date;
                            echo "</span>";
                if(!($i > $count)){
                echo "<hr  width='100%' noshade='#000'/>";
                }
                }
                }
                {/php}
            </td>
            <td>
                {empty name="driver_user.r_name"}
                新手
                {else /}
                {$driver_user.r_name}
                {/empty}
            </td>
            <td>
                {php}
                if($driver_user['tag']){
                $tag = Db::name('driver_tag')->where('id','in',$driver_user['tag'])->field('chinese')->select();
                $tagStr = '';
                foreach($tag as $tk=>$tv){
                $tagStr .= $tv['chinese'].',';
                }
                echo rtrim($tagStr,',');
                }
                {/php}
            </td>
        </tr>
        {/volist}
        {if !empty($driverInService)}
        <tr class="text-c">
            <td colspan="16">服务中的司机</td>
        </tr>
        {/if}
        {volist name="driverInService" id="drivers_in_services"}
        <tr class="text-c">
            <td><input type="radio" name="driver_user_id" value="{$drivers_in_services.user_id}" data-realname="{$drivers_in_services.realname}" data-user_id="{$drivers_in_services.user_id}" data-account="{$drivers_in_services.account}"></td>
            <td>{$drivers_in_services.user_id}</td>
            <td>{$drivers_in_services.realname}</td>
            <td>{$driver_user.nationality}</td>
            <td>{$drivers_in_services.phone}</td>
            <td>{$drivers_in_services.seats}</td>
            <td>
                {$drivers_in_services.arctic}
            </td>
            <td>
                {$drivers_in_services.brand_name}
            </td>
            <td>
                {$drivers_in_services.car_model}
            </td>
            <td>{$drivers_in_services.inservice?"服务中":"不在服务"}</td>
            <td>{php}echo count($drivers_in_services['dispatchOrder']); {/php}</td>
            <td    style="padding: 0px;">
                {php}
                if($drivers_in_services['dispatchOrder']){
                $count = count($drivers_in_services['dispatchOrder']);
                $i = 1;
                foreach($drivers_in_services['dispatchOrder'] as $key09=>$val09){
                $i++;
                $status = '';
                switch($val09['dispatch_group_status']){
                case 'undistributed'; $status = '未派单'; break;
                case 'sendorders'; $status = '待接单'; break;
                case 'proceed'; $status = '进行中'; break;
                case 'achieve'; $status = '已完成'; break;
                case 'accounts'; $status = '已结算'; break;
                }
                echo "<span>";
                        echo $val09['id'].':'.$status;
                        echo "</span>";
                if(!($i > $count)){
                echo "<hr  width='100%' noshade='#000'/>";
                }
                }
                }
                {/php}
            </td>
            <td    style="padding: 0px;">
                {php}
                if($drivers_in_services['dispatchOrder']){
                $count = count($drivers_in_services['dispatchOrder']);
                $i = 1;
                foreach($drivers_in_services['dispatchOrder'] as $key09=>$val09){
                $i++;
                $go_date = '';
                if(!empty($val09['go_date'])){
                $go_date = date('Y-m-d',$val09['go_date']);
                }
                echo "<span>";
                        echo $go_date;
                        echo "</span>";
                if(!($i > $count)){
                echo "<hr  width='100%' noshade='#000'/>";
                }
                }
                }
                {/php}
            </td>
            <td    style="padding: 0px;">
                {php}
                if($drivers_in_services['dispatchOrder']){
                $count = count($drivers_in_services['dispatchOrder']);
                $i = 1;
                foreach($drivers_in_services['dispatchOrder'] as $key22=>$val22){
                $i++;
                $end_date = '';
                if(!empty($val22['end_date'])){
                $end_date = date('Y-m-d',$val22['end_date']);
                }
                echo "<span>";
                        echo $end_date;
                        echo "</span>";
                if(!($i > $count)){
                echo "<hr  width='100%' noshade='#000'/>";
                }
                }
                }
                {/php}
            </td>
            <td>
                {empty name="drivers_in_services.r_name"}
                新手
                {else /}
                {$drivers_in_services.r_name}
                {/empty}
            </td>
            <td>
                {php}
                if($drivers_in_services['tag']){
                $tag = Db::name('driver_tag')->where('id','in',$drivers_in_services['tag'])->field('chinese')->select();
                $tagStr = '';
                foreach($tag as $tk=>$tv){
                $tagStr .= $tv['chinese'].',';
                }
                echo rtrim($tagStr,',');
                }
                {/php}
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
        <div class="page-bootstrap">{$page ?? ''}</div>
        <div class="row cl">
            <div class="col-xs-9 col-sm-8 col-xs-offset-4 col-sm-offset-5">
                <button type="submit" id="submit" class="btn btn-primary radius" onclick="submitSriver()">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
                <button type="button" class="btn btn-default radius ml-20" onClick="layer_close();">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__LIB__/Validform/5.3.2/Validform.min.js"></script>
<script type="text/javascript" src="__LIB__/template/template.js"></script>
<script>
    function submitSriver() {
        console.log('sdfdsf', $('#form55').serialize())
        $.ajax({
            type: 'post',
            url: '/admin/dispatch_traveler_group/reallocate',
            data: $('#form55').serializeArray(),
            success: function (data) {

                console.log('data', data);
                if (data.code == 1){
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                        // location.reload();
                    });
                }else{
                    layer.msg(data.msg);
                    window.parent.location.reload(); //刷新父页面
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引\
                    parent.layer.close(index)
                }
            }
        })
    }
    $(function () {
        $(function () {
            var tag = $("#tag").select2({
                language: "zh-CN", //设置 提示语言
                width: "100%", //设置下拉框的宽度
                theme: "classic"
            });
            {notempty name = "Request.param.tag"}
            tag.val("{$Request.param.tag}").trigger("change");
            {/notempty}
            })
        var driver_rank_id = $("#driver_rank_id").select2({
            language: "zh-CN", //设置 提示语言
            width: "100%", //设置下拉框的宽度
            theme: "classic"
        });
        {notempty name = "Request.param.driver_rank_id"}
        driver_rank_id.val("{$Request.param.driver_rank_id}").trigger("change");
        {/notempty}

    })
</script>
{/block}
